package com.tarena.demo.luban.all.main.component;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tarena.demo.luban.protocol.order.param.OrderAddParam;
import com.tarena.luban.demo.cart.api.CartRpcApi;
import org.apache.dubbo.rpc.RpcException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//@Component
public class CartRpcDeleteComponent {
    @Autowired
    private CartRpcApi cartRpcApi;
    @SentinelResource(value="cartDelete",blockHandler = "cartDeleteBlock")
    public void cartDelete(OrderAddParam param){
        try{
            Thread.sleep(200);
        }catch (Exception e){
        }
        cartRpcApi.cartDelete(param.getUserId(),param.getProductCode());
    }
    public void cartDeleteBlock(OrderAddParam param, BlockException e){
        //删除购物车失败 ,调用失败 时间过长 熔断降级
        System.out.println("删除购物车失败,当前购物车参数 userId"+param.getUserId()+
                "productCode"+param.getProductCode());
    }
}
